﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Serialization;

namespace TaskSystemClient
{
    public enum RepeatMode
    {
        Day,
        Week,
        Month,
        Year
    }
    public enum RepeatType
    {
        NoRepeat,
        AlwaysRepeat,
        RepeatNTimes
    }
    public class ShortTime
    {
        public int Hour { get; set; }
        public int Minute { get; set; }

        private static Regex ShortTimePattern;
        static ShortTime()
        {
            ShortTimePattern = new Regex(@"^\s*(\d+)\s*:\s*(\d+)\s*$", RegexOptions.Compiled);

        }
        public override string ToString()
        {
            return string.Format("{0} : {1}", Hour, Minute);
        }

        public static ShortTime Parse(string str)
        {
            Match m = ShortTimePattern.Match(str);
            if (!m.Success)
                return null;
            int hour = int.Parse(m.Groups[1].Value);
            int minute = int.Parse(m.Groups[2].Value);
            return new ShortTime { Hour = hour, Minute = minute };
        }

    }
    /**
     * 开始时间
     * 结束时间
     * 定期模式：按日，按周，按月，按年
     *  按日提醒 
     *  按周提醒 每个星期几
     *  按月提醒 每月几号
     *  按年提醒 每年几月几号
     * 重复模式
     *  开始时间
     *  重复方式：无结束日期，结束N次后，结束日期
     */
    class NotificationData
    {
        /// <summary>
        /// 开始时间， 格式 HH : MM
        /// </summary>
        [XmlAttribute]
        public string StartTime { get; set; }
        /// <summary>
        /// 结束时间，格式 HH : MM
        /// </summary>
        [XmlAttribute]
        public string EndTime { get; set; }
        /// <summary>
        /// 定期模式
        /// </summary>
        [XmlAttribute]
        public RepeatMode RepeatMode { get; set; }
        /// <summary>
        /// 星期几
        /// </summary>
        [XmlAttribute]
        public DayOfWeek DayOfWeek { get; set; }
        /// <summary>
        /// 每月的第几天
        /// </summary>
        [XmlAttribute]
        public int Day { get; set; }
        /// <summary>
        /// 每年的第几个月
        /// </summary>
        [XmlAttribute]
        public int Month { get; set; }
        /// <summary>
        /// 重复方式
        /// </summary>
        [XmlAttribute]
        public RepeatType RepeatType { get; set; }
        /// <summary>
        /// 重复次数
        /// </summary>
        [XmlAttribute]
        public int RepeatTimes { get; set; }
        /// <summary>
        /// 重复方式的结束日期
        /// </summary>
        [XmlAttribute]
        public DateTime RepeatEndTime { get; set; }


        public ShortTime GetStartTime()
        {
            return ShortTime.Parse(StartTime);

        }
        public ShortTime GetEndTime()
        {
            return ShortTime.Parse(EndTime);
        }
        public void Reset()
        {
            DateTime now = DateTime.Now;
            ShortTime startTime = new ShortTime();
            if (now.Minute >= 30)
            {
                startTime.Hour = now.Hour + 1;
                startTime.Minute = 0;
            }
            else
            {
                startTime.Hour = now.Hour;
                startTime.Minute = 30;
            }
            ShortTime endTime = new ShortTime { Hour = startTime.Hour + 1, Minute = startTime.Minute };
            this.StartTime = startTime.ToString();
            this.EndTime = endTime.ToString();
            this.RepeatMode = RepeatMode.Day;
            this.Day = now.Day;
            this.DayOfWeek = now.DayOfWeek;
            this.Month = now.Month;
            RepeatType = RepeatType.AlwaysRepeat;
            this.RepeatTimes = 1;
            RepeatEndTime = now + new TimeSpan(365, 0, 0, 0);            
        }
        public NotificationData()
        {
        }
    }


    class NotificationManager
    {
    }
}
